<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko">
<head>
	<title>Justification</title>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<link type="text/css" rel="stylesheet" href="../JSSpec.css" />
	<script type="text/javascript" src="../diff_match_patch.js"></script>
	<script type="text/javascript" src="../JSSpec.js"></script>
	<script type="text/javascript" src="../../javascripts/XQuared.js?load_others=1"></script>
</head>
<body>
<div style='position:absolute; height:0; margin:0; padding:0; overflow:hidden;'>
	<div id="editor"></div>
</div>

<script type="text/javascript" language="javascript">// <![CDATA[
describe('Simple justification', {
	'before': function() {
		rdom = xq.rdom.Base.createInstance();
		rdom.setWin(window);
		rdom.setRoot(xq.$('editor'));
	},
	'should justify center': function() {
		xq.$('editor').innerHTML = '<p>A</p>';
		var a = rdom.getRoot().firstChild;
		rdom.justifyBlock(a, 'center');
		value_of(xq.$('editor').innerHTML.normalizeHtml()).should_be('<p style="text-align: center;">A</p>');
	},
	'should justify right': function() {
		xq.$('editor').innerHTML = '<p>A</p>';
		var a = rdom.getRoot().firstChild;
		rdom.justifyBlock(a, 'right');
		value_of(xq.$('editor').innerHTML.normalizeHtml()).should_be('<p style="text-align: right;">A</p>');
	},
	'should justify both': function() {
		xq.$('editor').innerHTML = '<p>A</p>';
		var a = rdom.getRoot().firstChild;
		rdom.justifyBlock(a, 'both');
		value_of(xq.$('editor').innerHTML.normalizeHtml()).should_be('<p style="text-align: justify;">A</p>');
	},
	'should justify left': function() {
		xq.$('editor').innerHTML = '<p style="text-align: center;">A</p>';
		var a = rdom.getRoot().firstChild;
		rdom.justifyBlock(a, 'left');
		value_of(xq.$('editor').innerHTML.normalizeHtml()).should_be('<p>A</p>');
	}
})

describe('Nested blocks', {
	'before': function() {
		rdom = xq.rdom.Base.createInstance();
		rdom.setWin(window);
		rdom.setRoot(xq.$('editor'));
	},
	'should justify container when it is the only child': function() {
		xq.$('editor').innerHTML = '<div><p>A</p></div>';
		var target = rdom.getRoot().firstChild.firstChild;
		var affected = rdom.justifyBlock(target, 'center');
		
		value_of(affected).should_be(target.parentNode);
		value_of(xq.$('editor').innerHTML.normalizeHtml()).should_be('<div style="text-align: center;"><p>A</p></div>');
	},
	'should justify itself when it is not the only child': function() {
		xq.$('editor').innerHTML = '<div><p>A</p><p>B</p></div>';
		var target = rdom.getRoot().firstChild.firstChild;
		var affected = rdom.justifyBlock(target, 'center');
		
		value_of(affected).should_be(target);
		value_of(xq.$('editor').innerHTML.normalizeHtml()).should_be('<div><p style="text-align: center;">A</p><p>B</p></div>');
	}
})
// ]]></script>
</body>
</html>